//
//  RCButton.m
//  OCUIBootcamp
//
//  Created by 周晓旺 on 2023/11/29.
//

#import "RCButton.h"

@implementation RCButton

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    //    CGRect hitBounds = CGRectInset(self.bounds, 10, 10);
    CGRect hitBounds = UIEdgeInsetsInsetRect(self.bounds, self.touchInsets);
    NSString *hitPoint = NSStringFromCGPoint(point);
    NSString *expandedBounds = NSStringFromCGRect(hitBounds);
    BOOL boundsContainPoint = CGRectContainsPoint(hitBounds, point);
    NSLog(@"---RCButton的pointInside方法---");
    NSLog(@"hitPoint == %@" , hitPoint);
    NSLog(@"expandedBounds == %@", expandedBounds);
    NSLog(@"isContains == %d", boundsContainPoint);
    NSLog(@"---RCButton的pointInside方法---end");

    
    return CGRectContainsPoint(hitBounds, point);
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    CGRect hitBounds = UIEdgeInsetsInsetRect(self.bounds, self.touchInsets);
    if (CGRectContainsPoint(hitBounds, point)) {
        return self;
    }
    return  nil;
    //下面的方法是错的，要用下面的方法，返回nil则不会再调用pointInside方法了。
//    if (CGRectContainsPoint(self.bounds, point)) {
//        return self;
//    }
//    
//    return  nil;
}
@end
